package com.iqiyi.pps.epg.core.service.vod;

import com.iqiyi.pps.epg.api.model.web.query.TFilter;
import com.iqiyi.pps.epg.api.model.web.query.TPage;
import com.iqiyi.pps.epg.api.model.web.vod.TVodad;
import com.iqiyi.pps.epg.api.model.web.vod.TVodadPage;
import com.iqiyi.pps.epg.core.dao.base.Page;
import com.iqiyi.pps.epg.core.dao.base.PropertyFilter;
import com.iqiyi.pps.epg.core.dao.vod.VodadDataDao;
import com.iqiyi.pps.epg.core.model.vod.Vodad;
import com.iqiyi.pps.epg.core.utils.TransUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by zhangjing on 2017/10/9.
 */
@Service
@Transactional
public class VodadServiceImpl implements IVodadService {

    @Autowired
    private VodadDataDao dao;

    @Override
    public long add(Vodad entity) {
        dao.saveOnly(entity);
        return entity.getId();
    }

    @Override
    public void delByStatus(Long id) {
        Vodad entity = dao.get(id);
        entity.setStatus(-1);
        dao.save(entity);
    }

    @Override
    public TVodadPage findVodadList(TPage page, TFilter filter) {
        List<PropertyFilter> filterList = TransUtil.builderFilterList(filter);
        Page<Vodad> dbPage = TransUtil.buildPage(page);
        Page<Vodad> pageData = dao.findPage(dbPage, filterList);
        List<Vodad> dataList = pageData.getResult();
        TVodadPage tVodadPage = new TVodadPage();
        page.setTotalCount(pageData.getTotalCount());
        tVodadPage.setTPage(page);
        List<TVodad> list =dao.transToTList(dataList);
        tVodadPage.setResult(list);
        return tVodadPage;
    }
}
